package com.lc.advertising.ui.activity;

import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.hjq.bar.TitleBar;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.advertising.R;
import com.lc.advertising.app.AppActivity;
import com.lc.advertising.http.request.DanyeApi;
import com.lc.advertising.http.response.DanyeBean;
import com.lc.advertising.util.HtmlUtils;


import butterknife.BindView;
import butterknife.ButterKnife;

public class DanyeActivity extends AppActivity {
    @BindView(R.id.titlebar)
    TitleBar titlebar;
    @BindView(R.id.webview)
    WebView webview;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_danye;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        titlebar.setTitle(getIntent().getStringExtra("title"));
        WebSettings webSettings = webview.getSettings();
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setUseWideViewPort(true);//设置webview推荐使用的窗口
        webSettings.setLoadWithOverviewMode(true);//设置webview加载的页面的模式
        webSettings.setDisplayZoomControls(false);//隐藏webview缩放按钮
        webSettings.setJavaScriptEnabled(true); // 设置支持javascript脚本
        webview.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {


            }
        });
        danye();
    }

    private void danye() {
        EasyHttp.post(this)
                .api(new DanyeApi()
                        .setId(getIntent().getStringExtra("id")))
                .request(new HttpCallback<DanyeBean>(this) {
                    @Override
                    public void onSucceed(DanyeBean data) {
                        toast(data.getMessage());
                        if (data.getCode() == 200) {
                            String html = HtmlUtils.setHtml(data.getFind().getContent());
                            webview.loadDataWithBaseURL(null, html
                                    , "text/html", "UTF-8", null);
                        }
                    }


                });
    }
}
